import Vuex from 'vuex';
import Vue from 'vue';

Vue.use(Vuex)
const modulesFiles = require.context('./modules', true, /\.js$/)
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
  const value = modulesFiles(modulePath)
  modules[moduleName]=value.default
  modules[moduleName].namespaced = true;   //打开命名空间
  return modules
}, {})
export default new Vuex.Store({
  modules,
  state: {
    theme: "light"						//状态管理器state中的初始theme值设置为light
  },
  mutations: {
     // 设置切换主题
    // 设置切换主题
    setTheme(state, theme) {
      state.theme = theme;
      localStorage.setItem("air-conditioner-theme", theme);
      document.head
        .querySelector("#theme-link")
        .setAttribute("href", `./static/theme-${theme}.css`);
    },
    //获取缓存主题
    getTheme(state) {
      state.theme = localStorage.getItem("air-conditioner-theme") || "light";
      document.head
        .querySelector("#theme-link")
        .setAttribute("href", `./static/theme-${state.theme}.css`);
    },

      setCollapsed(state,value){
      },
  },
  actions: {
    getUserdata({commit}){

    },
    
  },
  
})
